/*
 * @description:
 * @version:
 * @Author: 王治飞
 * @Date: 2023-08-16 16:23:27
 * @LastEditors: 王治飞
 * @LastEditTime: 2023-08-22 14:55:18
 */
import { getHomeGoodPriceData, getHomeGoodDiscountData, getHotrecommenddestData, getLongforData, getPlusData } from '@/services/modules/home'
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'

export const fetchHomeDataAction = createAsyncThunk('fetchdata', (payload, { dispatch }) => {
  getHomeGoodPriceData().then(res => {
    dispatch(changeGoodPriceInfoAction(res))
  })
  getHomeGoodDiscountData().then(res => {
    dispatch(changeGoodDiscountInfoAction(res))
  })
  getHotrecommenddestData().then(res => {
    dispatch(changeHotrecommenddestDataAction(res))
  })

  getLongforData().then(res => {
    dispatch(changeLongforDataAction(res))
  })
  getPlusData().then(res => {
    dispatch(changePlusDataAction(res))
  })
})

const homeSlice = createSlice({
  name: 'home',
  initialState: {
    goodPriceInfo: {},
    goodDiscountInfo: {},
    hotrecommenddest: {},
    longforData: {},
    plusData: {}
  },
  reducers: {
    changeGoodPriceInfoAction(state, { payload }) {
      state.goodPriceInfo = payload
    },
    changeGoodDiscountInfoAction(state, { payload }) {
      state.goodDiscountInfo = payload
    },
    changeHotrecommenddestDataAction(state, { payload }) {
      state.hotrecommenddest = payload
    },
    changeLongforDataAction(state, { payload }) {
      state.longforData = payload
    },
    changePlusDataAction(state, { payload }) {
      state.plusData = payload
    }
  }
})
const { changeGoodPriceInfoAction, changeGoodDiscountInfoAction, changeHotrecommenddestDataAction, changeLongforDataAction, changePlusDataAction } = homeSlice.actions

export default homeSlice.reducer
